1201A - Important Exam - CodeForces Solution


implementation strings *900

Please click on ads to support us..

Python Code:

n,m = map(int,input().split())
li = []
for i in range(n):
    li.append(input())
score_arr = list(map(int,input().split()))
score = 0
for i in range(m):
    a,b,c,d,e = 0,0,0,0,0
    for j in range(n):
        if li[j][i]=='A':
            a+=1 
        elif li[j][i]=='B':
            b+=1 
        elif li[j][i]=='C':
            c+=1 
        elif li[j][i]=='D':
            d+=1 
        else:
            e+=1
    score = score+max(a,b,c,d,e)*score_arr[i]
print(score)

C++ Code:

#include<iostream>
#include<bits/stdc++.h>
#define el endl
#define ll long long
#define du double
#define all(v) v.begin(),v.end()
#define forme for(int i=0;i<x;i++){cin>>arr[i];}
#define fast ios_base::sync_with_stdio(false),cout.tie(NULL),cin.tie(NULL);
#define Omar_Ahmed_O_H_M codeforce
const int N = 1e9 + 5;
using namespace std;
int main(){
fast;
ll a,x,y,ans=0;
cin>>x>>y;
string s;
ll arr[20001][6],vec[y];
memset(arr,0,sizeof arr);
for(int i=0;i<x;i++)
  {cin>>s;
   for(int j=0;j<y;j++)
      arr[j][s[j]]++;
  }
  for(int i=0;i<y;i++){
        cin>>vec[i];
  }
for(int i=0;i<y;i++)
 {
  ll sum=0;
  for(char j='A';j<='E';j++)
    sum=max(sum,arr[i][j]);
  ans+=sum*vec[i];
 }
cout<<ans<<el;
}


Comments

Submit
0 Comments
More Questions

1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push